package com.tomecode.tools.maven.settings.model;

/**
 * Download policy
 * 
 * @author Frastia Tomas
 * 
 */
public final class Release {
	/**
	 * Whether to use this repository for downloading this type of artifact.
	 */
	private String enabled;
	/**
	 * The frequency for downloading updates - can be "always", "daily"
	 * (default), "interval:XXX" (in minutes) or "never" (only if it doesn't
	 * exist locally).
	 */
	private UpdatePolicy updatePolicy;
	/**
	 * 
	 */
	private int updatePolicyInterval = 0;
	/**
	 * What to do when verification of an artifact checksum fails - warn, fail,
	 * etc. Valid values are "fail" or "warn".
	 */
	private ChecksumPolicy checksumPolicy;

	public Release() {

	}

	public final UpdatePolicy getUpdatePolicy() {
		return updatePolicy;
	}

	public final void setUpdatePolicy(String updatePolicy) {
		this.updatePolicy = UpdatePolicy.parse(updatePolicy);
		if (this.updatePolicy == UpdatePolicy.INTERVAL) {
			updatePolicyInterval = UpdatePolicy.parseInterval(updatePolicy);
		}
	}

	public final ChecksumPolicy getChecksumPolicy() {
		return checksumPolicy;
	}

	public final void setChecksumPolicy(String checksumPolicy) {
		this.checksumPolicy = ChecksumPolicy.parse(checksumPolicy);
	}

	public final String getEnabled() {
		return enabled;
	}

	public final void setEnabled(String enabled) {
		this.enabled = enabled;
	}

	public final boolean isEnabled() {
		return Boolean.parseBoolean(enabled);
	}
	
	public final int getUpdatePolicyInterval(){
		return updatePolicyInterval;
	}

	public final String makeUpdatePolicy() {
		if (updatePolicy == UpdatePolicy.INTERVAL) {
			return UpdatePolicy.getInterval(updatePolicyInterval);
		}
		return updatePolicy.toString();
	}

}
